﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using System.IO;
using AR.Web.Services;
using AR.Validation;
using AR.Entities;
using AR.ViewModel.Candidat;
using System.Collections.ObjectModel;
using AR.ViewModels;
using AR.Models;
using System.Windows.Markup;
using System.Threading;

namespace AR.Views.Candidat
{
    public partial class CreationCandidat : Page
    {
        public CreationCandidatViewModel ViewModel
        {
            get { return this.LayoutRoot.DataContext as CreationCandidatViewModel; }
        }
    
        public CreationCandidat()
        {
            //this.NavigationCacheMode = NavigationCacheMode.Disabled;
            //this.Language = XmlLanguage.GetLanguage(Thread.CurrentThread.CurrentCulture.Name);
            InitializeComponent();
           
            this.Loaded += PageLoaded;
            

            
        }

        private void PageLoaded(object sender, RoutedEventArgs e)
        {
            int id=0;
            if (NavigationContext.QueryString.Count()>0)
                id = int.Parse(NavigationContext.QueryString["id"]);

            this.DataContext = new CreationCandidatViewModel(id);
        }
        //protected override void OnNavigatedTo(NavigationEventArgs e)
        //{
        //    base.OnNavigatedTo(e);

        //    if ( NavigationContext.QueryString["id"] != null)
        //    {
        //        this.ViewModel.Initialise(NavigationContext.QueryString["id"]);
        //    }
        //}
        private void LayoutRoot_BindingValidationError(object sender, ValidationErrorEventArgs e)
        {
            if (e.Action == ValidationErrorEventAction.Added)
            {
                (e.OriginalSource as Control).Background = new SolidColorBrush(Colors.Yellow);
            }
            if (e.Action == ValidationErrorEventAction.Removed)
            {
                (e.OriginalSource as Control).Background = new SolidColorBrush(Colors.White);

            }

        }

      
        
        

      



    }

}